<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
$lotto_id = intval( $_GET['id'] );
$order_id = intval( $_GET['order'] );
$conf = new Config();
$stopbet = $conf->get( "waitbet" );
if ( !isset( $_SESSION['saywaitmod'] ) )
{
    $_SESSION['saywaitmod'] = 0;
}
$saystopmod = $_SESSION['saywaitmod'];
if ( $stopbet <= date( "Hi" ) && !$saystopmod )
{
    $saystopmod = 1;
    $_SESSION['saywaitmod'] = $saystopmod;
    echo "-1";
    exit();
}
$norder = $order_id;
$split = 1;
$ratemod = 1;
$disk_code = "a";
$diskStr = "";
include( "class_6h/BetTotal_6h.php" );
$BetTotal_6h = new BetTotal_6h( $lotto_id );
$dataTotalArr = array();
$showDataArr = array();
$total_win = array();
$theacl = $curruser['acl'];
$userid = $curruser['id'];
$showid = $theacl == 255 ? "0" : $userid;
$betids = array( 1003 );
$bettypeStr = "1003";
$betsGame = "1003";
$dataTotalArr[$betsGame] = array( "bettype" => $betsGame, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
$sql = $BetTotal_6h->getDataListTotalSQL( $lotto_id, $bettypeStr, $showid, $split, $diskStr, " AND numbers LIKE '{$norder},%'" );
$totalRs = getdb( $sql );
while ( !$totalRs->eof )
{
    $tempIdx = $totalRs->f['bettype'];
    $dataTotalArr[$tempIdx] = $totalRs->f;
    $totalRs->next();
}
$totalRs->close();
$lostwin = array();
$winlost = $dataTotalArr[$betsGame]['amount'] - $dataTotalArr[$betsGame]['back1'] + $dataTotalArr[$betsGame]['back2'];
$total_win[$order_id][$betsGame] = $dataTotalArr[$betsGame]['amount'] - $dataTotalArr[$betsGame]['back1'] + $dataTotalArr[$betsGame]['back2'];
$i = 1;
while ( $i < 50 )
{
    $showDataArr[$betsGame][$i] = array( "numbers" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => $winlost, "namount" => "" );
    $lostwin[$betsGame][$i] = $winlost;
    ++$i;
}
$sql = $BetTotal_6h->getDataListByNumSsSQL( $lotto_id, $bettypeStr, $showid, $diskStr, $split, $ratemod );
$sql .= " AND numbers LIKE '{$norder},%'";
$rs = getdb( $sql );
$updatetime = systime( ) - 30;
while ( !$rs->eof )
{
    $bettype = $rs->f['bettype'];
    $i = intval( substr( $rs->f['numbers'], 2 ) );
    $winlost = $dataTotalArr[$bettype]['amount'] - $rs->f['amount_rate'] - $dataTotalArr[$bettype]['back1'] + $dataTotalArr[$bettype]['back2'];
    $lostwin[$bettype][$i] = $winlost;
    $showDataArr[$bettype][$i]['totalnum'] = $rs->f['totalnum'];
    $showDataArr[$bettype][$i]['amount'] = $rs->f['amount'];
    $showDataArr[$bettype][$i]['amount_rate'] = $rs->f['amount_rate'];
    $showDataArr[$bettype][$i]['rate'] = $rs->f['rate'];
    $rs->next();
}
$rs->close();
$rateIdx = "r";
$rs = getdb( "select * from rate4{$norder}{$disk_code} where lotto_id={$lotto_id}" );
$i = 1;
while ( $i < 50 )
{
    $showDataArr[$betsGame][$i]['rate'] = $rs->f[$rateIdx.d2( $i )] - 0;
    ++$i;
}
$rs->close();
if ( isset( $showDataArr[$betsGame] ) && 0 < $dataTotalArr[$betsGame]['amount'] )
{
    asort( $lostwin[$betsGame] );
    reset( $lostwin[$betsGame] );
    $k = 1;
    $showDataArrTemp = array();
    foreach ( $lostwin[$betsGame] as $key => $val )
    {
        $showDataArrTemp[$betsGame][$k] = $showDataArr[$betsGame][$key];
        ++$k;
    }
    $showDataArr[$betsGame] = $showDataArrTemp[$betsGame];
}
echo $order_id."@".$total_win[$order_id][$betsGame];
$i = 1;
while ( $i < 50 )
{
    echo ",".$showDataArr[$betsGame][$i]['numbers']."@".$showDataArr[$betsGame][$i]['rate']."@".$showDataArr[$betsGame][$i]['totalnum']."@".$showDataArr[$betsGame][$i]['amount'];
    echo "@".$showDataArr[$betsGame][$i]['amount_rate'];
    ++$i;
}
echo "\n";
include( "class_6h/class.menu.php" );
$fieldArr = array( "lotto_id" => $lotto_id, "split_id" => 1 );
$onlineMenu = new menu_6h( 1, $fieldArr );
echo $onlineMenu->getMenuAmu();
echo "\n";
exit();
?>